package org.javaopenaccess.service.session;

import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javassist.Loader;

import org.javaopenaccess.model.InternalSession;
import org.javaopenaccess.model.Schema;

public class InternalSessionService implements SessionService{
	
	private Map<String, InternalSession> sessions = new HashMap<String, InternalSession>();
	
	@Override
	public InternalSession createSession(Schema schema) {
		InternalSession session = new InternalSession();
		session.setSessionId(UUID.randomUUID().toString());
		session.setCurrentSchema(schema);
		session.setSessionStartTime(new GregorianCalendar().getTimeInMillis());
		session.setClassLoader(new Loader());
		sessions.put(session.getSessionId(), session);
		return session;
	}
	@Override
	public InternalSession getSession(String id){
		return sessions.get(id);
	}
	
}
